﻿using System.Collections.Generic;
using NPersistence;

namespace EstimateTracker.Domain.Entities
{
    [Entity]
    [NamedQuery(Name = "FindByActivityId", Query = "FROM Task t WHERE t.Activity.Id = :Id")]
    [NamedQuery(Name = "FindActualsForTask", Query = "SELECT SUM(h.Hours) FROM Task t JOIN t.HoursWorked h WHERE t.Id = :Id GROUP BY t.Id")]
    [NamedQuery(Name = "FindActualsForDay", Query = "SELECT t.Activity.Project.Name,t.Activity.Name,t.Name,t.EstimatedHours,SUM(h.Hours) as Actual FROM Task t JOIN t.HoursWorked h WHERE h.DateAndTimeFinished >= :TodaysDateStart AND h.DateAndTimeFinished <= :TodaysDateEnd GROUP BY t.Name,t.EstimatedHours,t.Activity.Name,t.Activity.Project.Name ORDER BY t.Activity.Project.Name,t.Activity.Name")]
    public class Task
    {
        [Id][GeneratedValue]
        public virtual int Id { get; set; }

        [Column]
        public virtual string Name { get; set; }

        [Column]
        public virtual double EstimatedHours { get; set; }

        [ManyToOne]
        [JoinColumn(Name = "Activity_id")]
        public virtual Activity Activity { get; set; }

        [OneToMany(MappedBy = "Task")]
        public virtual IList<HoursWorked> HoursWorked { get; set; }
    }
}